﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LX.Web.Excel;
using S4Store.Domain.AfterSaleKpi;

namespace S4Store.Domain.AfterSaleReport
{
    public class SPReport: ExportObject
    {

        #region 数据导出
        public override bool? Discriminate(string propertyname)
        {
            //StandardConfig.
            return null;
        }
        #endregion


        public int Year { get; set; }
        public int Month { get; set; }
        public int Day { get; set; }

        public MonthStandardConfig StandardConfig { get; set; }

        public List<SparePartsMonthInput> M { get; set; }

        public Store Store { get; set; }

        protected bool showlastday = false;
        public virtual void ShowLastDay(bool value)
        {
            showlastday = value;
        }

        [Export("月份")]
        public decimal YF
        {
            get;
            set;
        }

        [Export("库存成本总量目标")]
        public decimal KCCBZLMB
        {
            get
            {
                return M.Sum(o => o.KCCBZL);
            }
        }

        [Export("月初库存成本")]
        public decimal YCKCCB
        {
            get
            {
                return M.Sum(o => o.YCKCCB);
            }
        }

        [Export("月末库存成本")]
        public decimal YMKCCB
        {
            get
            {
                return M.Sum(o => o.YMKCCB);
            }
        }

        [Export("本月库存均值")]
        public decimal BYKCJZ
        {
            get
            {
                return (YCKCCB + YMKCCB) / 2;

            }
        }
        [Export("日均备件销售成本")]
        public decimal RJBJXSCB
        {
            get
            {
                return M.Sum(o => o.RJBJXSCB);

            }
        }
        [Export("月备件销售成本")]
        public decimal YBJXSCB
        {
            get
            {
                return M.Sum(o => o.YBJXSCB);

            }
        }
        [Export("月计划订货成本")]
        public decimal YJHDHCB
        {
            get
            {
                return M.Sum(o => o.YJHDHCB);

            }
        }

        [Export("月全部订货成本")]
        public decimal YQBDHCB
        {
            get
            {
                return M.Sum(o => o.YQBDHCB);

            }
        }

        [Export("月备件收入")]
        public decimal YBJSR
        {
            get
            {
                return M.Sum(o => o.YBJSR);

            }
        }

        [Export("月均保修备件收入")]
        public decimal YJBXBJSR
        {
            get
            {
                return M.Sum(o => o.YJBXBJSR);

            }
        }

        [Export("呆滞库存备件成本")]
        public decimal DZKBJCB
        {
            get
            {
                return M.Sum(o => o.DZKCBJCB);

            }
        }

        [Export("死库存备件成本")]
        public decimal SKCBJCB
        {
            get
            {
                return M.Sum(o => o.SKCBJCB);

            }
        }

        [Export("申请保修总件数")]
        public int SQBXZJS
        {
            get
            {
                return M.Sum(o => o.SQBXZJS);

            }
        }

        [Export("保修合格件数")]
        public int BXHGJS
        {
            get
            {
                return M.Sum(o => o.BXHGJS);

            }
        }

        [Export("缺件未维修台次")]
        public int QJWWXTC
        {
            get
            {
                return M.Sum(o => o.QJWWXTC);

            }
        }

        [Export("月维修总台次")]
        public int YWXZTC
        {
            get
            {
                return M.Sum(o => o.YWXZTC);

            }
        }

        [Export("回收零件总数")]
        public int HSLJZS
        {
            get
            {
                return M.Sum(o => o.HSLJZS);

            }
        }

        [Export("发出零件总数")]
        public int FCLJZS
        {
            get
            {
                return M.Sum(o => o.FCLJZS);

            }
        }

        [Export("平均在库天数")]
        public decimal PJZKTS
        {
            get
            {
                if (RJBJXSCB == 0) return 0;
                return KCCBZLMB / (decimal)RJBJXSCB;

            }
        }

        [Export("备件周转率")]
        public decimal BJZZL
        {
            get
            {
                if (BYKCJZ == 0) return 0;
                return YBJXSCB * 12 / (decimal)BYKCJZ;
            }
        }

        [Export("备件保修合格率", Format = "{0}%")]
        public decimal BJBXHGL
        {
            get
            {
                if (SQBXZJS == 0) return 0;
                return BXHGJS / (decimal)SQBXZJS;
            }
        }

        [Export("呆库存率", Format = "{0}%")]
        public decimal DKCL
        {
            get
            {
                if (KCCBZLMB == 0) return 0;
                return DZKBJCB / (decimal)KCCBZLMB*100;
            }
        }

        [Export("死库存率", Format = "{0}%")]
        public decimal SKCL
        {
            get
            {
                if (KCCBZLMB == 0) return 0;
                return SKCBJCB / (decimal)KCCBZLMB*100;
            }
        }

        [Export("呆库存变化率", Format = "{0}%")]
        public decimal DKCBHL
        {
            get
            {
                return 0;
            }
        }

        [Export("死库存变化率", Format = "{0}%")]
        public decimal SKCBHL
        {
            get
            {
                return 0;
            }
        }

        [Export("正常订货率", Format = "{0}%")]
        public decimal ZCDHL
        {
            get
            {
                if (YQBDHCB == 0) return 0;
                return (YJHDHCB / (decimal)YQBDHCB) * 100;
            }
        }

        [Export("备件满足率", Format = "{0}%")]
        public decimal BJMZL
        {
            get
            {
                if (YWXZTC == 0) return 0;
                return (1 - (decimal)QJWWXTC / (decimal)YWXZTC) * 100;
            }
        }

        [Export("零件回收及时率", Format = "{0}%")]
        public decimal LJHSJSL
        {
            get
            {
                if (FCLJZS == 0) return 0;
                return (decimal)HSLJZS / (decimal)FCLJZS * 100;
            }
        }

    }
}
